﻿using System;
using System.Threading;

namespace Solidi
{
    sealed class LazyDependencyFactory<T> : GenericDependencyFactory
    {
        public override object Build(IDependencyContainer container, IDependencyKey key)
        {
            GenericDependencyFactory builder = new FuncDependencyFactory<T>();

            return new Lazy<T>((Func<T>)builder.Build(container, key), LazyThreadSafetyMode.ExecutionAndPublication);
        }
    }
}